home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / S / sfCL Update.cpt / sfCL Update / CFontSizeDial.p next >
Encoding:
Text File  |  1990-10-22  |  4.6 KB  |  125 lines  |  [TEXT/PJMM]

  1. {****************************************************}
  2. {}
  3. {        CFontSizeDial.p                                                                        }
  4. {}
  5. {        Dialog object to handle user font size selection.                                        }
  6. {}
  7. {        Copyright © 1990, Stanley Fertig.  All rights reserved.                    }
  8. {}
  9. {****************************************************}
  10.  
  11.  
  12. unit CFontSizeDial;                           {Object for choose-your-own fontSize dialog box}
  13.  
  14. interface
  15.  
  16.     uses
  17.         TCL, sfCL, LottoIntf;
  18. {----------------------------------------------------------------------------}
  19.  
  20. implementation
  21.  
  22.     const
  23.         EditBoxNumber = 5;
  24. {----------------------------------------------------------------------------}
  25.  
  26.     procedure CFontSizeDial.IDialog (DIALid: integer; aFloating: Boolean; anEnclosure: CDesktop; aSupervisor: CBureaucrat; Beep, DoCenter: boolean);
  27.         var                                          {procedure to initialize the dialog object}
  28.             theType: integer;
  29.             theItemHandle: Handle;
  30.             theBox: Rect;
  31.             aSize: integer;
  32.             aTextInfo: TextInfoRec;
  33.     begin
  34.         if member(aSupervisor, CFontDocument) then    {make sure the document uses Fonts...}
  35.             begin
  36.                 inherited IDialog(DIALid, aFloating, anEnclosure, aSupervisor, Beep, DoCenter);  {initialize the standard dialog object, using the appropriate resource #}
  37.  
  38.                 CTextEnvirons(CFontDocument(itsSupervisor).itsMainPane.itsEnvironment).GetTextInfo(aTextInfo);  {get Text Environment of Document}
  39.                 with aTextInfo do
  40.                     aSize := theSize;                          {Initialize text box to existing font size.}
  41.  
  42.                 GetDItem(Self.macPort, EditBoxNumber, theType, theItemHandle, theBox); {Get textbox}
  43.                 SetIText(theitemHandle, stringof(aSize : 1));                                             {change number to string}
  44.                 SelIText(Self.macPort, EditBoxNumber, kSelStart, kSelEnd)                       {Put string in textbox}
  45.             end
  46.         else  {if the Document doesn't use fonts, then just beep.}
  47.             Sysbeep(1)
  48.     end;
  49. {----------------------------------------------------------------------------}
  50.  
  51.     function CFontSizeDial.Filter (thedial: DialogPtr; var anEvent: EventRecord; var itemNumber: integer): boolean;
  52.         var
  53.             chCode: integer;
  54.             ch: char;
  55.             cmdDown: boolean;
  56.     begin
  57.         if anEvent.what in [keydown, AutoKey] then
  58.             begin
  59.                 Filter := true;
  60.                 with anEvent do
  61.                     begin
  62.                         chCode := BitAnd(message, CharCodeMask);
  63.                         ch := chr(chCode);
  64.                         cmdDown := (BitAnd(modifiers, CmdKey) <> 0)
  65.                     end;
  66.  
  67.                 if not cmdDown then
  68.                     begin
  69.                         if (chCode in [$8, $9, $3, $D, $30..$39]) then         {List your 'Acceptable' keys here}
  70.                             Filter := inherited Filter(thedial, anEvent, itemNumber)
  71.                         else
  72.                             begin
  73.                                 Sysbeep(1);
  74.                                 itemNumber := 0;
  75.                             end
  76.                     end
  77.                 else  {if Command Key is down}
  78.                     Filter := inherited Filter(thedial, anEvent, itemNumber)
  79.             end
  80.         else  {if not Keyboard Event}
  81.             Filter := inherited Filter(thedial, anEvent, itemNumber)
  82.     end;
  83. {----------------------------------------------------------------------------}
  84.  
  85.     procedure CFontSizeDial.DoAlert;   {After dialog is on screen, get user response.}
  86.         const
  87.             maxSize = 200;                           {arbitrary largest font size we accept}
  88.             CancelButton = 3;
  89.         var
  90.             theItem: integer;
  91.             theItemHandle: Handle;
  92.             theType: integer;
  93.             theBox: Rect;
  94.             oldValue: integer;
  95.             theString: str255;
  96.             aTextInfo: TextInfoRec;
  97.     begin
  98.         InitCursor;
  99.         repeat
  100.             ModalDialog(@DialFilter, theItem);                {Use customized filter procedure}
  101.         until theItem in [AltcmdQuit, OK, CancelButton];  {User clicked in either OK or Cancel buttons, or typed command-Q}
  102.  
  103.         if theItem = OK then {Clicked in OK button}
  104.             begin
  105.                 GetDItem(Self.macPort, EditBoxNumber, theType, theItemHandle, theBox);  {Get handle to text box}
  106.                 GetIText(theitemHandle, theString);      {Get text in textbox}
  107.                 oldValue := IntVal(theString);                {Convert text to integer}
  108.                 if (oldValue in [1..maxSize]) then         {Acceptable integer?}
  109.                     begin
  110.                         CTextEnvirons(CFontDocument(itsSupervisor).itsMainPane.itsEnvironment).GetTextInfo(aTextInfo);
  111.                         with aTextInfo do
  112.                             theSize := oldValue;      {Change font size in Environment record}
  113.                         CTextEnvirons(CFontDocument(itsSupervisor).itsMainPane.itsEnvironment).SetTextInfo(aTextInfo);    {Save changed Environment record}
  114.                         CStaticText(CFontDocument(itsSupervisor).itsMainPane).SetFontSize(oldValue)      {Change font size in Static Text record}
  115.                     end
  116.                 else   {if integer not within acceptable range then beep}
  117.                     Sysbeep(1)
  118.             end;
  119.         Self.Free;         {Get rid of Dialog & Object}
  120.         if theItem = AltcmdQuit then      {Did User type Command-Q? if so, then Quit Application.}
  121.             gApplication.DoCommand(cmdQuit)
  122.     end;
  123. {----------------------------------------------------------------------------}
  124.  
  125. end.